﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace Ordering_system.管理员界面
{
    public partial class Addeat : Form
    {
        public Addeat()
        {
            InitializeComponent();
        }

        private void Addeat_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void Addeat_Load(object sender, EventArgs e)
        {
            
        }
        string photoname;
        private void button1_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string acomodity = Aname.Text;//商品名
            string productType = acombox.Text;//类型
            //string proNum = acount.Text;
            
            decimal proPrice = decimal.Parse(aprice.Text);//价格
                                                          // string upTime = adatatime.Text.ToString();
         
          string photoname=label5.Text;

            //连接字符产
            string StringConn = "Data Source=.;Initial Catalog=sweet_1;Integrated Security=True";
            //创建对象
            SqlConnection conn = new SqlConnection(StringConn);

            //创建sql语句
            string sql = string.Format("select * from Food_table");
            SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);
            adapter.Fill(ds);
            conn.Close();
            conn.Dispose();
            //商品重复检测
            DataTable dt = ds.Tables[0];
            List<string> list = new List<string>();
            int index = 0;
            int ondex = 0;
            bool repeat = false;
            
            String sqlinser = String.Format("insert into Food_table values('{0}',{1},'{2}','{3}')", acomodity, proPrice, productType, photoname);

                bool retinser = Ordering_system.DBHelper.ExecuteNonQuery(sqlinser);
                if (retinser)
                {
                    MessageBox.Show("操作成功");
                }
            }
        

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //打开文件夹浏览
            using (OpenFileDialog imgfile=new OpenFileDialog())
            {
                //如果选择ok
                if (imgfile.ShowDialog() == DialogResult.OK)
                {
                    //把选到的文件名拿过来
                    string fileName = imgfile.FileName;
                    //把图片路径设置为来源于他的名字
                    
                    this.pictureBox1.Image=Image.FromFile(fileName);
                    //赋值到另一个变量。
                    label5.Text=fileName;
                }
            }
                   
        }
    }
}
